//
//  FBDLoginViewController.m
//  baodongPro
//
//  Created by feng on 16/3/14.
//  Copyright © 2016年 proper. All rights reserved.
//
#define WallImageURL @"http://b165.photo.store.qq.com/psb?/V14QOrBo08YdxO/Crwydnua*iwDZViwIrxCKTaeUmMeefj2U3hzdt27XJY!/b/dFYdX2LVGgAA&bo=WAIgA7AEQAYBCKQ!&rf=viewer_4.JPG"

#import "FBDLoginViewController.h"
#import "UIView+FBDQuickCreateUI.h"
#import "UMSocial.h"
@interface FBDLoginViewController ()

@end
#define titleFont [UIFont systemFontOfSize:13]
@implementation FBDLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    UITapGestureRecognizer* doubleTapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapGestureDismess:)];
    [doubleTapGesture setNumberOfTapsRequired:2];
    [self.view addGestureRecognizer:doubleTapGesture];
    [self creatQQloginAndWeChatLoginButtonUI];
    
    
    
    
    
}

#pragma private  创建QQ WeChat 登陆的UI

-(void)creatQQloginAndWeChatLoginButtonUI
{

    UIImageView* wallImageView=[self.view fbd_quickCreateUIImageViewWithFrame:CGRectMake(0, 0, ScreenW, ScreenH) withImageName:WallImageURL];
    [self.view addSubview:wallImageView];
    
    
    NSValue* QQValue=[NSValue valueWithCGRect:CGRectMake(40, 100, 40, 40)];
    NSValue* WeiXinValue=[NSValue valueWithCGRect:CGRectMake(40, 300, 40, 40)];
    NSArray* buttonFrameArray=@[QQValue,WeiXinValue];
    
    
    UIButton* QQLoginButton=[self.view fbd_quickCreateUIButtonWithFrame:[[buttonFrameArray objectAtIndex:0]CGRectValue]];
    [QQLoginButton addTarget:self action:@selector(qqLoginButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [QQLoginButton setBackgroundImage:[UIImage imageNamed:@"UMSocialSDKResourcesNew.bundle/SnsPlatform/UMS_qq_icon@2x.png"] forState:UIControlStateNormal];
    QQLoginButton.titleEdgeInsets=UIEdgeInsetsMake(33, 0, 0, 0);
    QQLoginButton.titleLabel.font=titleFont;
    [QQLoginButton  setTitle:@"QQ" forState:UIControlStateNormal];
    QQLoginButton.backgroundColor=[UIColor clearColor];
    [self.view addSubview:QQLoginButton];
    
    UIButton* WeiXinLoginButton=[self.view fbd_quickCreateUIButtonWithFrame:[[buttonFrameArray objectAtIndex:1]CGRectValue]];
    [WeiXinLoginButton addTarget:self action:@selector(weiXinLoginButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [WeiXinLoginButton setBackgroundImage:[UIImage imageNamed:@"UMSocialSDKResourcesNew.bundle/SnsPlatform/UMS_wechat_icon@2x.png"] forState:UIControlStateNormal];
    WeiXinLoginButton.titleEdgeInsets=UIEdgeInsetsMake(33, 0, 0, 0);
    [WeiXinLoginButton  setTitle:@"微信" forState:UIControlStateNormal];
    WeiXinLoginButton.backgroundColor=[UIColor clearColor];
    WeiXinLoginButton.titleLabel.font=titleFont;
    [self.view addSubview:WeiXinLoginButton];
    
}

#pragma mark ----event  第三方登陆授权
-(void)qqLoginButtonPressed:(UIButton*)sender
{
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQzone];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToQzone];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
            [self dismissViewControllerAnimated:YES completion:nil];
            
            
        }
        
    });
}
-(void)weiXinLoginButtonPressed:(UIButton*)sender
{
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToWechatSession];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            [self dismissViewControllerAnimated:YES completion:nil];
            
            
            
        }
        
    });
}
-(void)doubleTapGestureDismess:(UITapGestureRecognizer*)tap
{
[self dismissViewControllerAnimated:YES completion:^{
   
    NSLog(@"dismissViewControllerAnimated");
    
}];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
